home *** CD-ROM | disk | FTP | other *** search
/ Komputer for Alle 2004 #2 / K-CD-2-2004.ISO / OpenOffice Sv / f_0397 / python-core-2.2.2 / lib / test / test_cookie.py < prev    next >
Encoding:
Python Source  |  2003-07-18  |  1.3 KB  |  48 lines

  1. # Simple test suite for Cookie.py
  2.  
  3. from test_support import verify, verbose, run_doctest
  4. import Cookie
  5.  
  6. # Currently this only tests SimpleCookie
  7.  
  8. cases = [
  9.     ('chips=ahoy; vienna=finger', {'chips':'ahoy', 'vienna':'finger'}),
  10.     ('keebler="E=mc2; L=\\"Loves\\"; fudge=\\012;";',
  11.      {'keebler' : 'E=mc2; L="Loves"; fudge=\012;'}),
  12.  
  13.     # Check illegal cookies that have an '=' char in an unquoted value
  14.     ('keebler=E=mc2;', {'keebler' : 'E=mc2'})
  15.     ]
  16.  
  17. for data, dict in cases:
  18.     C = Cookie.SimpleCookie() ; C.load(data)
  19.     print repr(C)
  20.     print str(C)
  21.     items = dict.items()
  22.     items.sort()
  23.     for k, v in items:
  24.         print ' ', k, repr( C[k].value ), repr(v)
  25.         verify(C[k].value == v)
  26.         print C[k]
  27.  
  28. C = Cookie.SimpleCookie()
  29. C.load('Customer="WILE_E_COYOTE"; Version=1; Path=/acme')
  30.  
  31. verify(C['Customer'].value == 'WILE_E_COYOTE')
  32. verify(C['Customer']['version'] == '1')
  33. verify(C['Customer']['path'] == '/acme')
  34.  
  35. print C.output(['path'])
  36. print C.js_output()
  37. print C.js_output(['path'])
  38.  
  39. # Try cookie with quoted meta-data
  40. C = Cookie.SimpleCookie()
  41. C.load('Customer="WILE_E_COYOTE"; Version="1"; Path="/acme"')
  42. verify(C['Customer'].value == 'WILE_E_COYOTE')
  43. verify(C['Customer']['version'] == '1')
  44. verify(C['Customer']['path'] == '/acme')
  45.  
  46. print "If anything blows up after this line, it's from Cookie's doctest."
  47. run_doctest(Cookie)
  48.